package selenium;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.testng.*;
import org.testng.annotations.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class DeleteFilm extends selenium.pages.TestBase {
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Test
  public void testDeleteFilm() throws Exception {    
	  
	driver.get(baseUrl + "/php4dvd/");
	
	selenium.LoginTest.testLogin(); 
	
// Cancel Delete	
	
	WebElement Film = 
	driver.findElement(By.xpath("//img[@title='Fury']"));
	Film.click();
 
    driver.findElement(By.xpath("//img[@alt='Remove']")).click();
    
    Alert alert1 = 
    driver.switchTo().alert();
    alert1.getText();
    alert1.dismiss();
    
// Delete    
    
    driver.findElement(By.xpath("//img[@alt='Remove']")).click();
    
    Alert alert2 = 
    driver.switchTo().alert();
    alert2.getText();
    alert2.accept();
    
// Check Film deleted   
    
    driver.get(baseUrl + "/php4dvd/");
    Assert.assertFalse(isElementPresent(By.xpath("//img[@title='Fury']")));      
    
  }   

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  
  }  

@AfterMethod
public static void SiteLogout() throws Exception {
	
	selenium.LogoutTest.testLogout();
	       
}  

}
  
